package com.example.myapplication.ui.Home.adapter;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.myapplication.R;
import com.example.myapplication.model.bean.DownloadData;
import com.example.myapplication.ui.wight.OnClickListener;
import com.example.myapplication.utils.ImageLoaderUtils;

import java.util.List;

/**
 * Created by yin97 on 2017/6/26.
 */

public class ContentAdapter extends BaseQuickAdapter<DownloadData> {
  private   OnClickListener mListener;
    private ProgressBar progressBar;

    public ContentAdapter(int layoutResId, List<DownloadData> data,OnClickListener listener) {
        super(layoutResId, data);
        this.mListener=listener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, DownloadData downloadData) {
        ImageView imageView= baseViewHolder.getView(R.id.imageview);
        ImageLoaderUtils.display(mContext,imageView,downloadData.getLogo_url());
        ( (TextView)baseViewHolder.getView(R.id.title)).setText(downloadData.getName());
        ( (TextView)baseViewHolder.getView(R.id.tv_context)).setText("版本："+downloadData.getVersion_name());
        ( (TextView)baseViewHolder.getView(R.id.btn)).setText("版本："+downloadData.getVersion_name());
          progressBar= ( (ProgressBar)baseViewHolder.getView(R.id.progressBar));
        if (downloadData.isShowProgress()){
            setProgressBar(downloadData.getProgress());
            progressBar.setVisibility(View.VISIBLE);
        }else {
            progressBar.setVisibility(View.GONE);

        }
        ( (Button)baseViewHolder.getView(R.id.btn)).setText(downloadData.getStateText());

        if (downloadData.isShowProgress()){

            ( (TextView)baseViewHolder.getView(R.id.count)).setVisibility(View.GONE);
        }else {
            ( (TextView)baseViewHolder.getView(R.id.count)).setText("大小："+downloadData.getSize_fixed()+"MB");
            ( (TextView)baseViewHolder.getView(R.id.count)).setVisibility(View.VISIBLE);
        }
        ( (Button)baseViewHolder.getView(R.id.btn)).setOnClickListener(v -> {
        mListener.onClick(downloadData,baseViewHolder.getAdapterPosition(),v);
        });
    }

    public  void  setProgressBar(int progress){
        progressBar.setProgress(progress);
    }
}
